import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 不使用additionalData，避免Sass警告
      }
    }
  },
  server: {
    port: 3000,
    proxy: {
      '/dify': {
        target: 'https://api.dify.ai/v1',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dify/, ''),
        cors: true
      },
      '/jdoodle-api': {
        target: 'https://api.jdoodle.com/v1',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/jdoodle-api/, ''),
        cors: true,
        headers: {
          'Content-Type': 'application/json'
        }
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: true,
    chunkSizeWarningLimit: 2000,
    rollupOptions: {
      output: {
        manualChunks: {
          'vendor': [
            'vue',
            'vue-router',
            'pinia',
            'vant'
          ],
          'editor': [
            'monaco-editor'
          ]
        }
      }
    }
  },
  optimizeDeps: {
    include: ['vue', 'vue-router', 'pinia', 'vant'],
    exclude: []
  }
})